﻿/**这个文件保存ajax传递与返回的信息事件函数
*/

/** 定义消息枚举*/
var MsgEvent={};
MsgEvent.SNull = "0";
MsgEvent.PInfo = "1";
MsgEvent.Citie = "2";
MsgEvent.Wild = "3";
MsgEvent.LevalScene = "4";
MsgEvent.GotoPlace = "5";
MsgEvent.Search_Monster = "6";
MsgEvent.GetItems = "7";
MsgEvent.SceneInfo = "8";
MsgEvent.SendSceneC = "9";
MsgEvent.ShopItemList = "10";
MsgEvent.ShopBuyItem = "11";
MsgEvent.ShopSellItem = "12";

var MsgDicFunc = {
    "0": sucNull,
    "1": sucPlayer,
    "2": sucCitie,
    "3": sucWild,
    "6": sucFigher,
    "7": sucItems,
    "8": sucScene,
    "10": sucShopItemList,
    "11": sucShopBuyRev,
    "12": sucShopBuyRev,
}

function ajaxSuccess(xml) {
    var data = xml.split("|");
    var sevent = data[0];
    var smsg = data[1];
    //转化成对象
    eval("var vdata = "+smsg);
    //传入
    MsgDicFunc[String(sevent)](vdata);
}

function ajaxError(xml) {
    alert('数据读取失败!' + xml);
}

function ajaxMsg(str_msg, str_data) {
    $.ajax({
        url: 'Game/ClientMsg',
        type: 'GET',
        data: { msg: str_msg, data: str_data },
        //dataType: 'xml', //这里可以不写，但千万别写text或者html!!!
        timeout: 1000,
        error: ajaxError,
        success: ajaxSuccess,
    });
}

function sucNull(obj){
}

//返回了玩家的信息
function sucPlayer(obj){
    GF_PlayerInfo.update(obj);
}

//返回场景信息
function sucScene(obj){
    //第一次游戏
    EventDrama.begin(obj);
    //更新场景
    GF_SceneMgr.update(obj);

    
}

//返回城市信息
function sucCitie(clist) {
    GF_City.update(clist);
    GF_City.show();
}

//返回野外区域信息
function sucWild(clist) {
    GF_Wild.update(clist);
    GF_Wild.show();
}
//玩家背包道具信息
function sucItems(ilist){
    GF_Bags.update(ilist);
    GF_Bags.show();
}
//商店商品信息列表
function sucShopItemList(obj){
    GF_ShopItems.update(obj);
}
//购买商品反馈
function sucShopBuyRev(obj){
    alert(obj.msg);
    GF_ShopItems.hide_msgdialog();
}


var gfight_txt = null;
function sucFigher(obj)
{
    if (gfight_txt != null)
        gfight_txt.destroy();
    //alert("战斗: "+obj.msg);
    var bpx = 250;
    var bpy = 100;
    gfight_txt = new F5Frame.Text().Create({text:obj.msg, x:250, y:100, align:"left", color:"#ffffff"});
    GF_SceneMgr.nForm.appendChild(gfight_txt);
    for(x in obj.data){
        fdata = obj.data[x];
        var txt = new F5Frame.Text().Create({text:fdata.msg, x:0, y:15+15*Number(x), align:"left", color:"#ffffff"});
        gfight_txt.appendChild(txt);
    }
}